package yk.com.AllMenu;

import yk.com.Student;
import yk.com.StudentManager;
import java.util.Scanner;

public class AddStudent {
    public static void execute(Scanner scanner) {
        System.out.println("请输入学生信息：");
        String id = "";
        boolean isValidId = false;

        // 检查学号是否重复
        while (!isValidId) {
            System.out.print("学号: ");
            id = scanner.nextLine();

            if (!StudentManager.isStudentIdExists(id)) {
                isValidId = true;
            } else {
                System.out.println("该学号已经存在，请重新输入！");
            }
        }

        System.out.print("姓名: ");
        String name = scanner.nextLine();

        System.out.print("年龄: ");
        int age = scanner.nextInt();
        scanner.nextLine(); // 消耗换行符

        System.out.print("住址: ");
        String address = scanner.nextLine();

        // 创建学生对象并添加到集合中
        Student student = new Student(id, name, age, address);
        StudentManager.addStudent(student);
    }
}